var ctx=window.daijia.ctx;
var driverId=window.daijia.driverId;

$(document).ready(function(){
	
	var newDate = new Date();
	var startDate = new Date();
	startDate.setDate(startDate.getDate()-30);
	var startTimeStr=startDate.getFullYear()+"-"+((startDate.getMonth()+1)>9?(startDate.getMonth()+1):'0' + (startDate.getMonth()+1))+"-"+(startDate.getDate()>9?startDate.getDate():'0' + startDate.getDate())+" "+"00:00";
	var endTimeStr=newDate.getFullYear()+"-"+((newDate.getMonth()+1)>9?(newDate.getMonth()+1):'0' + (newDate.getMonth()+1))+"-"+(newDate.getDate()>9?newDate.getDate():'0' + newDate.getDate())+" "+"00:00";
	$("#daiStartTime").val(startTimeStr);
	$("#daiEndTime").val(endTimeStr);
	
	$("#errandStartTime").val(startTimeStr);
	$("#errandEndTime").val(endTimeStr);
	
	$("#zhuanStartTime").val(startTimeStr);
	$("#zhuanEndTime").val(endTimeStr);
	
	$("#freightStartTime").val(startTimeStr);
	$("#freightEndTime").val(endTimeStr);
	$("#zhuanxianStartTime").val(startTimeStr);
	$("#zhuanxianEndTime").val(endTimeStr);
	
	$("#daiStartTime").datetimepicker({
        format: "yyyy-mm-dd HH:ii",
        language: 'zh-CN',
        showMeridian: true,
        autoclose: true,
        todayBtn: true
    });
	$("#daiEndTime").datetimepicker({
		format: "yyyy-mm-dd HH:ii",
        language: 'zh-CN',
        showMeridian: true,
        autoclose: true,
        todayBtn: true
    });
	$("#errandStartTime").datetimepicker({
        format: "yyyy-mm-dd HH:ii",
        language: 'zh-CN',
        showMeridian: true,
        autoclose: true,
        todayBtn: true
    });
	$("#errandEndTime").datetimepicker({
		format: "yyyy-mm-dd HH:ii",
        language: 'zh-CN',
        showMeridian: true,
        autoclose: true,
        todayBtn: true
    });
	$("#zhuanStartTime").datetimepicker({
        format: "yyyy-mm-dd HH:ii",
        language: 'zh-CN',
        showMeridian: true,
        autoclose: true,
        todayBtn: true
    });
	$("#zhuanEndTime").datetimepicker({
		format: "yyyy-mm-dd HH:ii",
        language: 'zh-CN',
        showMeridian: true,
        autoclose: true,
        todayBtn: true
    });
	$("#freightStartTime").datetimepicker({
		format: "yyyy-mm-dd HH:ii",
        language: 'zh-CN',
        showMeridian: true,
        autoclose: true,
        todayBtn: true
    });
	$("#freightEndTime").datetimepicker({
        format: "yyyy-mm-dd HH:ii",
        language: 'zh-CN',
        showMeridian: true,
        autoclose: true,
        todayBtn: true
    });
	$("#zhuanxianStartTime").datetimepicker({
		format: "yyyy-mm-dd HH:ii",
		language: 'zh-CN',
		showMeridian: true,
		autoclose: true,
		todayBtn: true
	});
	$("#zhuanxianEndTime").datetimepicker({
		format: "yyyy-mm-dd HH:ii",
		language: 'zh-CN',
		showMeridian: true,
		autoclose: true,
		todayBtn: true
	});
	

	//点击搜索
	$("#zhuan_search_button").click(function(){
		if($("#zhuanStartTime").val()=="" || $("#zhuanEndTime").val()==""){
			$.scojs_message("日期不能为空", $.scojs_message.TYPE_ERROR);
			return false;
		}
		var DATE_FORMAT = /^[0-9]{4}-[0-1]{1}[0-9]{1}-[0-3]{1}[0-9]{1} [0-2]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/;
		if(!DATE_FORMAT.test($("#zhuanStartTime").val()) || !DATE_FORMAT.test($("#zhuanEndTime").val())){
		   $.scojs_message("您输入的日期格式有误，正确格式应为：2012-01-01 08:30", $.scojs_message.TYPE_ERROR);
		   return false;
		}
		if($("#zhuanStartTime").val()>$("#zhuanEndTime").val()){
			 $.scojs_message("开始日期不能大于结束日期", $.scojs_message.TYPE_ERROR);
			 return false;
		}
		
		$("#zhuanDateRangeText").text($("#zhuanStartTime").val()+" 至 "+$("#zhuanEndTime").val());
		$("#zhuanDateRangeButton").parent().find(".dropdown-calendar").hide();
		
		var newTotalElements=getZhuanTotalElements();
		zhuanInitPagedata(newTotalElements);
		$(".z").each(function(index,element){
			$(element).find("li a").html("共 "+newTotalElements+" 条数据");
		});
	});
	$("#dai_search_button").click(function(){
		if($("#daiStartTime").val()=="" || $("#daiEndTime").val()==""){
			$.scojs_message("日期不能为空", $.scojs_message.TYPE_ERROR);
			return false;
		}
		var DATE_FORMAT = /^[0-9]{4}-[0-1]{1}[0-9]{1}-[0-3]{1}[0-9]{1} [0-2]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/;
		if(!DATE_FORMAT.test($("#daiStartTime").val()) || !DATE_FORMAT.test($("#daiEndTime").val())){
		   $.scojs_message("您输入的日期格式有误，正确格式应为：2012-01-01 08:30", $.scojs_message.TYPE_ERROR);
		   return false;
		}
		if($("#daiStartTime").val()>$("#daiEndTime").val()){
			 $.scojs_message("开始日期不能大于结束日期", $.scojs_message.TYPE_ERROR);
			 return false;
		}
		
		$("#daiDateRangeText").text($("#daiStartTime").val()+" 至 "+$("#daiEndTime").val());
		$("#daiDateRangeButton").parent().find(".dropdown-calendar").hide();
		
		var newTotalElements=getDaiTotalElements();
		daiInitPagedata(newTotalElements);
		$(".d").each(function(index,element){
			$(element).find("li a").html("共 "+newTotalElements+" 条数据");
		});
	});
	$("#errand_search_button").click(function(){
		if($("#errandStartTime").val()=="" || $("#errandEndTime").val()==""){
			$.scojs_message("日期不能为空", $.scojs_message.TYPE_ERROR);
			return false;
		}
		var DATE_FORMAT = /^[0-9]{4}-[0-1]{1}[0-9]{1}-[0-3]{1}[0-9]{1} [0-2]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/;
		if(!DATE_FORMAT.test($("#errandStartTime").val()) || !DATE_FORMAT.test($("#errandEndTime").val())){
		   $.scojs_message("您输入的日期格式有误，正确格式应为：2012-01-01 08:30", $.scojs_message.TYPE_ERROR);
		   return false;
		}
		if($("#errandStartTime").val()>$("#errandEndTime").val()){
			 $.scojs_message("开始日期不能大于结束日期", $.scojs_message.TYPE_ERROR);
			 return false;
		}
		
		$("#errandDateRangeText").text($("#errandStartTime").val()+" 至 "+$("#errandEndTime").val());
		$("#errandDateRangeButton").parent().find(".dropdown-calendar").hide();
		
		var newTotalElements=getErrandTotalElements();
		errandInitPagedata(newTotalElements);
		$(".e").each(function(index,element){
			$(element).find("li a").html("共 "+newTotalElements+" 条数据");
		});
	});
	$("#freight_search_button").click(function(){
		if($("#freightStartTime").val()=="" || $("#freightEndTime").val()==""){
			$.scojs_message("日期不能为空", $.scojs_message.TYPE_ERROR);
			return false;
		}
		var DATE_FORMAT = /^[0-9]{4}-[0-1]{1}[0-9]{1}-[0-3]{1}[0-9]{1} [0-2]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/;
		if(!DATE_FORMAT.test($("#errandStartTime").val()) || !DATE_FORMAT.test($("#errandEndTime").val())){
		   $.scojs_message("您输入的日期格式有误，正确格式应为：2012-01-01 08:30", $.scojs_message.TYPE_ERROR);
		   return false;
		}
		if($("#freightStartTime").val()>$("#freightEndTime").val()){
			 $.scojs_message("开始日期不能大于结束日期", $.scojs_message.TYPE_ERROR);
			 return false;
		}
		
		$("#freightDateRangeText").text($("#freightStartTime").val()+" 至 "+$("#freightEndTime").val());
		$("#freightDateRangeButton").parent().find(".dropdown-calendar").hide();
		
		var newTotalElements=getFreightTotalElements();
		freightInitPagedata(newTotalElements);
		$(".f").each(function(index,element){
			$(element).find("li a").html("共 "+newTotalElements+" 条数据");
		});
	});
	$("#zhuanxian_search_button").click(function(){
		if($("#zhuanxianStartTime").val()=="" || $("#zhuanxianEndTime").val()==""){
			$.scojs_message("日期不能为空", $.scojs_message.TYPE_ERROR);
			return false;
		}
		var DATE_FORMAT = /^[0-9]{4}-[0-1]{1}[0-9]{1}-[0-3]{1}[0-9]{1} [0-2]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/;
		if(!DATE_FORMAT.test($("#zhuanxianStartTime").val()) || !DATE_FORMAT.test($("#zhuanxianEndTime").val())){
			$.scojs_message("您输入的日期格式有误，正确格式应为：2012-01-01 08:30", $.scojs_message.TYPE_ERROR);
			return false;
		}
		if($("#zhuanxianStartTime").val()>$("#zhuanxianEndTime").val()){
			$.scojs_message("开始日期不能大于结束日期", $.scojs_message.TYPE_ERROR);
			return false;
		}
		
		$("#zhuanxianDateRangeText").text($("#zhuanxianStartTime").val()+" 至 "+$("#zhuanxianEndTime").val());
		$("#zhuanxianDateRangeButton").parent().find(".dropdown-calendar").hide();
		
		var newTotalElements=getZhuanxianTotalElements();
		zhuanxianInitPagedata(newTotalElements);
		$(".f").each(function(index,element){
			$(element).find("li a").html("共 "+newTotalElements+" 条数据");
		});
	});
	if(zhuanche){
		zhuanInitPagedata(getZhuanTotalElements());
	}
	if(errand){
		errandInitPagedata(getErrandTotalElements());
	}
	if(zhuanxian){
		zhuanxianInitPagedata(getZhuanxianTotalElements());
	}
    if(dj){
    	daiInitPagedata(getDaiTotalElements());
    }
    if(freight){
    	freightInitPagedata(getFreightTotalElements());
    }
	
	
	
//	//点击全部
//	$("#clear_button").click(function(){
//		$("#title").val("");
//		$("#startTime").val("");
//		$("#endTime").val("");
//		$('#dateRangeCalendar').DatePickerClear();
//		$('#dateRangeText').text("选择时间");
//		$("#dateRangeButton").parent().find(".dropdown-calendar").hide();
//		
//		var newTotalElements=loadData(1);
//		initPagedata(newTotalElements,false);
//		$(".pageshow").each(function(index,element){
//			$(element).find("li a").html("共 "+newTotalElements+" 条数据");
//		});
//	});
	
	/*//导出。。。。。。。。
	//点击选择时间
	$("#exportDateRangeButton").click(function(){
		var dropdowncalendar=$(this).parent().find(".dropdown-calendar");
		if(dropdowncalendar.is(':hidden')){
			dropdowncalendar.show();
			if(dropdowncalendar.find(".datepicker").length==0){
				$('#exportDateRangeCalendar').DatePicker({
					flat: true,
					date: newDate,
					current: newDate,
					calendars: 3,
					mode: 'range',
					starts: 1,
					onChange: function(formated, dates){
						$("#exportStartTime").val(formated[0]);
						$("#exportEndTime").val(formated[1]);
					}
				});
			}
		}
		else{
			dropdowncalendar.hide();
		}
	});
	*/
	//点击应用
	/*$("#exportApplyIt").click(function(){
		if($("#exportStartTime").val()=="" && $("#exportEndTime").val()==""){
			$("#exportDateRangeText").text("请选择");
		}
		else{
			$("#exportDateRangeText").text($("#exportStartTime").val()+" 至 "+$("#exportEndTime").val());
		}
		$("#exportDateRangeButton").parent().find(".dropdown-calendar").hide();
	});*/
	
	//点击清空
	/*$("#exportClearIt").click(function(){
		$("#exportStartTime").val("");
		$("#exportEndTime").val("");
		$('#exportDateRangeCalendar').DatePickerClear();
		$("#exportApplyIt").click();
	});
	*/
	//导出数量
	/*$("#allAmount").click(function(){
		if($(this).is(':checked')){
			$("#amounts").attr("disabled",true);
		}
		else{
			$("#amounts").attr("disabled",false);
		}
	});*/
	
	//开始导出
	$("#export_button").click(function(){
		
		window.location=ctx+"/chart/exportDetail?"+$("#ExportForm").serialize();
	});
	
});

function zhuanLoadData(page){
	
	if($('#zhuanloadblacklayer').length==0){
		var dw = $(".table").width();
		var dh = $(".table").height();
		var backlayer ="<div id='zhuanloadblacklayer'><div style='margin-top:"+(dh/2)+"px;margin-left:"+(dw/2)+"px;'><img src='"+ctx+"/assets/css/images/loading.gif' /></div></div>"
		$(".table tbody").append(backlayer);
		$('#zhuanloadblacklayer').css({"z-index":"9","background":"#000","opacity":"0.5","position":'absolute',"top":0,"width":dw,"height":dh});
	}
	
	var off_set=(page-1)*20;
	var newcontent = '';
	var newTotalElements=0;
	
	$.ajax({
        url : ctx+'/chart/driverOrderDetailDate',
        type:'GET',
        async:true,
        dataType : 'json',
        data : {
        	"pager.offset":off_set,
        	"driverId":driverId,
        	"startTime":$("#zhuanStartTime").val(),
        	"type":"zhuanche",
        	"endTime":$("#zhuanEndTime").val(),
        	
        },
        success : function(result){
        	if(null!=result.zhuan && result.zhuan.totalElements>0){
        newcontent+="<tbody style='display:none;'>";
        		$(result.zhuan.content).each(function(index,data){
        			
	    newcontent+="<tr>"+
						"<td>"+new Date(data.finishTime).Format("yyyy-MM-dd hh:mm")+"</td>"+
						"<td>"+data.orderNum+"</td>"+
						"<td><span style='color:#ff950b;font-weight:700;'>"+data.money+"</span></td>"+
						"<td><span style='color:#ff950b;font-weight:700;'>"+data.ticheng+"</span></td>"+
					"</tr>";
        		});
        newcontent+="</tbody>";
        	}
        	$('#zhuanloadblacklayer').remove();
        	$(".zhuanTable tbody").remove();
        	$(".zhuanTable").append(newcontent);
        	$(".zhuanTable tbody").show(300);
    		if(null!=result.zhuan){
        		newTotalElements=result.zhuan.totalElements;
        	}
        }
	});
	
	return newTotalElements;
}
function zhuanxianLoadData(page){
	
	if($('#zhuanxianloadblacklayer').length==0){
		var dw = $(".table").width();
		var dh = $(".table").height();
		var backlayer ="<div id='zhuanxianloadblacklayer'><div style='margin-top:"+(dh/2)+"px;margin-left:"+(dw/2)+"px;'><img src='"+ctx+"/assets/css/images/loading.gif' /></div></div>"
		$(".table tbody").append(backlayer);
		$('#zhuanxianloadblacklayer').css({"z-index":"9","background":"#000","opacity":"0.5","position":'absolute',"top":0,"width":dw,"height":dh});
	}
	
	var off_set=(page-1)*20;
	var newcontent = '';
	var newTotalElements=0;
	
	$.ajax({
		url : ctx+'/chart/driverOrderDetailDate',
		type:'GET',
		async:true,
		dataType : 'json',
		data : {
			"pager.offset":off_set,
			"driverId":driverId,
			"type":"zhuanxian",
			"startTime":$("#zhuanxianStartTime").val(),
			"endTime":$("#zhuanxianEndTime").val(),
			
		},
		success : function(result){
			var newcontent = "";
			if(null!=result.zhuanxian && result.zhuanxian.totalElements>0){
				newcontent+="<tbody style='display:none;'>";
				$(result.zhuanxian.content).each(function(index,data){
					
					newcontent+="<tr>"+
					"<td>"+new Date(data.finishTime).Format("yyyy-MM-dd hh:mm")+"</td>"+
					"<td>"+data.orderNum+"</td>"+
					"<td><span style='color:#ff950b;font-weight:700;'>"+data.money+"</span></td>"+
					"<td><span style='color:#ff950b;font-weight:700;'>"+data.ticheng+"</span></td>"+
					"</tr>";
				});
				newcontent+="</tbody>";
			}
			$('#zhuanxianloadblacklayer').remove();
			$(".zhuanxianTable tbody").remove();
			$(".zhuanxianTable").append(newcontent);
			console.debug(newcontent);
			$(".zhuanxianTable tbody").show(300);
			if(null!=result.zhuanxian){
				newTotalElements=result.zhuanxian.totalElements;
			}
		}
	});
	
	return newTotalElements;
}
function freightLoadData(page){
	
	if($('#freightloadblacklayer').length==0){
		var dw = $(".table").width();
		var dh = $(".table").height();
		var backlayer ="<div id='freightloadblacklayer'><div style='margin-top:"+(dh/2)+"px;margin-left:"+(dw/2)+"px;'><img src='"+ctx+"/assets/css/images/loading.gif' /></div></div>"
		$(".table tbody").append(backlayer);
		$('#freightloadblacklayer').css({"z-index":"9","background":"#000","opacity":"0.5","position":'absolute',"top":0,"width":dw,"height":dh});
	}
	
	var off_set=(page-1)*20;
	var newcontent = '';
	var newTotalElements=0;
	
	$.ajax({
        url : ctx+'/chart/driverOrderDetailDate',
        type:'GET',
        async:true,
        dataType : 'json',
        data : {
        	"pager.offset":off_set,
        	"driverId":driverId,
			"type":"freight",
        	"startTime":$("#freightStartTime").val(),
        	"endTime":$("#freightEndTime").val(),
        	
        },
        success : function(result){
        	if(null!=result.freight && result.freight.totalElements>0){
        newcontent+="<tbody style='display:none;'>";
        		$(result.freight.content).each(function(index,data){
	    newcontent+="<tr>"+
						"<td>"+new Date(data.finishTime).Format("yyyy-MM-dd hh:mm")+"</td>"+
						"<td>"+data.orderNum+"</td>"+
						"<td><span style='color:#ff950b;font-weight:700;'>"+data.money+"</span></td>"+
						"<td><span style='color:#ff950b;font-weight:700;'>"+data.ticheng+"</span></td>"+
					"</tr>";
        		});
        newcontent+="</tbody>";
        	}
        	$('#freightloadblacklayer').remove();
        	$(".freightTable tbody").remove();
        	$(".freightTable").append(newcontent);
        	$(".freightTable tbody").show(300);
        	if(null!=result.freight){
        		newTotalElements=result.freight.totalElements;
        	}
        }
	});
	
	return newTotalElements;
}

function freightInitPagedata(total){
	$(".freightpagedata").paging(total, {
		format: '[< ncnnn >]',
		perpage: 20,
		onSelect: function (page) {
			freightLoadData(page);
	    	return false;
		},
		onFormat: function (type) {
			switch (type) {
			case 'block': // n and c
				if (!this.active)
					return '';
				else if (this.value != this.page)
					return '<li><a href="#">' + this.value + '</a></li>';
				return '<li class="active"><a href="#">' + this.value + '</a></li>';
			case 'next': // >
				return '<li><a href="#">&rsaquo;</a><li>';
			case 'prev': // <
					return '<li><a href="#">&lsaquo;</a><li>';
			case 'first': // [
					return '<li><a href="#">&laquo;</a><li>';
			case 'last': // ]
					return '<li><a href="#">&raquo;</a></li>';
			}
		}
	});
}
function zhuanxianInitPagedata(total){
	$(".zhuanxianpagedata").paging(total, {
		format: '[< ncnnn >]',
		perpage: 20,
		onSelect: function (page) {
			zhuanxianLoadData(page);
			return false;
		},
		onFormat: function (type) {
			switch (type) {
			case 'block': // n and c
				if (!this.active)
					return '';
				else if (this.value != this.page)
					return '<li><a href="#">' + this.value + '</a></li>';
				return '<li class="active"><a href="#">' + this.value + '</a></li>';
			case 'next': // >
				return '<li><a href="#">&rsaquo;</a><li>';
			case 'prev': // <
				return '<li><a href="#">&lsaquo;</a><li>';
			case 'first': // [
				return '<li><a href="#">&laquo;</a><li>';
			case 'last': // ]
				return '<li><a href="#">&raquo;</a></li>';
			}
		}
	});
}

//分页初始化
function zhuanInitPagedata(total){
	$(".zhuanpagedata").paging(total, {
		format: '[< ncnnn >]',
		perpage: 20,
		onSelect: function (page) {
			zhuanLoadData(page);
	    	return false;
		},
		onFormat: function (type) {
			switch (type) {
			case 'block': // n and c
				if (!this.active)
					return '';
				else if (this.value != this.page)
					return '<li><a href="#">' + this.value + '</a></li>';
				return '<li class="active"><a href="#">' + this.value + '</a></li>';
			case 'next': // >
				return '<li><a href="#">&rsaquo;</a><li>';
			case 'prev': // <
					return '<li><a href="#">&lsaquo;</a><li>';
			case 'first': // [
					return '<li><a href="#">&laquo;</a><li>';
			case 'last': // ]
					return '<li><a href="#">&raquo;</a></li>';
			}
		}
	});
}

function daiLoadData(page){
	
	if($('#loadblacklayer').length==0){
		var dw = $(".table").width();
		var dh = $(".table").height();
		var backlayer ="<div id='loadblacklayer'><div style='margin-top:"+(dh/2)+"px;margin-left:"+(dw/2)+"px;'><img src='"+ctx+"/assets/css/images/loading.gif' /></div></div>"
		$(".daiTable tbody").append(backlayer);
		$('#loadblacklayer').css({"z-index":"9","background":"#000","opacity":"0.5","position":'absolute',"top":0,"width":dw,"height":dh});
	}
	
	var off_set=(page-1)*20;
	var newcontent = '';
	var newTotalElements=0;
	
	$.ajax({
        url : ctx+'/chart/driverOrderDetailDate',
        type:'GET',
        async:true,
        dataType : 'json',
        data : {
        	"pager.offset":off_set,
        	"driverId":driverId,
			"type":"daijia",
        	"startTime":$("#daiStartTime").val(),
        	"endTime":$("#daiEndTime").val(),
        	
        },
        success : function(result){
        	
        	if(null!=result.daijia && result.daijia.totalElements>0){
        newcontent+="<tbody style='display:none;'>";
        		$(result.daijia.content).each(function(index,data){
        			
	    newcontent+="<tr>"+
						"<td>"+data.finishTimeStr+"</td>"+
						"<td>"+data.orderNum+"</td>"+
						"<td><span style='color:#ff950b;font-weight:700;'>"+data.money+"</span></td>"+
						"<td><span style='color:#ff950b;font-weight:700;'>"+data.ticheng+"</span></td>"+
					"</tr>";
        		});
        newcontent+="</tbody>";
        	}
        	$('#loadblacklayer').remove();
        	$(".daiTable tbody").remove();
        	$(".daiTable").append(newcontent);
        	$(".daiTable tbody").show(300);
        	if(null!=result.daijia){
        		newTotalElements=result.daijia.totalElements;
        	}
    		
        }
	});
	
	return newTotalElements;
}

//分页初始化
function daiInitPagedata(total){
	$(".daipagedata").paging(total, {
		format: '[< ncnnn >]',
		perpage: 20,
		onSelect: function (page) {
			daiLoadData(page);
	    	return false;
		},
		onFormat: function (type) {
			switch (type) {
			case 'block': // n and c
				if (!this.active)
					return '';
				else if (this.value != this.page)
					return '<li><a href="#">' + this.value + '</a></li>';
				return '<li class="active"><a href="#">' + this.value + '</a></li>';
			case 'next': // >
				return '<li><a href="#">&rsaquo;</a><li>';
			case 'prev': // <
					return '<li><a href="#">&lsaquo;</a><li>';
			case 'first': // [
					return '<li><a href="#">&laquo;</a><li>';
			case 'last': // ]
					return '<li><a href="#">&raquo;</a></li>';
			}
		}
	});
}

function errandLoadData(page){
	
	if($('#errandloadblacklayer').length==0){
		var dw = $(".table").width();
		var dh = $(".table").height();
		var backlayer ="<div id='errandloadblacklayer'><div style='margin-top:"+(dh/2)+"px;margin-left:"+(dw/2)+"px;'><img src='"+ctx+"/assets/css/images/loading.gif' /></div></div>"
		$(".errandTable tbody").append(backlayer);
		$('#errandloadblacklayer').css({"z-index":"9","background":"#000","opacity":"0.5","position":'absolute',"top":0,"width":dw,"height":dh});
	}
	
	var off_set=(page-1)*20;
	var newcontent = '';
	var newTotalElements=0;
	
	$.ajax({
        url : ctx+'/chart/driverOrderDetailDate',
        type:'GET',
        async:true,
        dataType : 'json',
        data : {
        	"pager.offset":off_set,
        	"driverId":driverId,
			"type":"errand",
        	"startTime":$("#errandStartTime").val(),
        	"endTime":$("#errandEndTime").val(),
        	
        },
        success : function(result){
        	if(null!=result.errand && result.errand.totalElements>0){
        newcontent+="<tbody style='display:none;'>";
        		$(result.errand.content).each(function(index,data){
        			
	    newcontent+="<tr>"+
						"<td>"+new Date(data.finishTime).Format("yyyy-MM-dd hh:mm")+"</td>"+
						"<td>"+data.orderNum+"</td>"+
						"<td><span style='color:#ff950b;font-weight:700;'>"+data.money+"</span></td>"+
						"<td><span style='color:#ff950b;font-weight:700;'>"+data.ticheng+"</span></td>"+
					"</tr>";
        		});
        newcontent+="</tbody>";
        	}
        	$('#errandloadblacklayer').remove();
        	$(".errandTable tbody").remove();
        	$(".errandTable").append(newcontent);
        	$(".errandTable tbody").show(300);
        	if(null!=result.errand){
        		newTotalElements=result.errand.totalElements;
        	}
        }
	});
	
	return newTotalElements;
}

//分页初始化
function errandInitPagedata(total){
	$(".errandpagedata").paging(total, {
		format: '[< ncnnn >]',
		perpage: 20,
		onSelect: function (page) {
			errandLoadData(page);
	    	return false;
		},
		onFormat: function (type) {
			switch (type) {
			case 'block': // n and c
				if (!this.active)
					return '';
				else if (this.value != this.page)
					return '<li><a href="#">' + this.value + '</a></li>';
				return '<li class="active"><a href="#">' + this.value + '</a></li>';
			case 'next': // >
				return '<li><a href="#">&rsaquo;</a><li>';
			case 'prev': // <
					return '<li><a href="#">&lsaquo;</a><li>';
			case 'first': // [
					return '<li><a href="#">&laquo;</a><li>';
			case 'last': // ]
					return '<li><a href="#">&raquo;</a></li>';
			}
		}
	});
}

function getDaiTotalElements(){
	var newTotalElements=0;
	$.ajax({
        url : ctx+'/chart/driverOrderDetailCount',
        type:'GET',
        async:false,
        dataType : 'json',
        data : {
        	"driverId":driverId,
        	"startTime":$("#daiStartTime").val(),
        	"endTime":$("#daiEndTime").val()
        },
        success : function(result){
        	newTotalElements=result.daijia.totalElements;
        	$(".d").each(function(index,element){
    			$(element).find("li a").html("共 "+newTotalElements+" 条数据");
    		});
        }
	});
	
	return newTotalElements;
}

function getErrandTotalElements(){
	var newTotalElements=0;
	$.ajax({
        url : ctx+'/chart/driverOrderDetailCount',
        type:'GET',
        async:false,
        dataType : 'json',
        data : {
        	"driverId":driverId,
        	"startTime":$("#errandStartTime").val(),
        	"endTime":$("#errandEndTime").val()
        },
        success : function(result){
        	newTotalElements=result.errand.totalElements;
        	$(".e").each(function(index,element){
    			$(element).find("li a").html("共 "+newTotalElements+" 条数据");
    		});
        }
	});
	
	return newTotalElements;
}

function getZhuanTotalElements(){
	var newTotalElements=0;
	$.ajax({
        url : ctx+'/chart/driverOrderDetailCount',
        type:'GET',
        async:false,
        dataType : 'json',
        data : {
        	"driverId":driverId,
        	"startTime":$("#zhuanStartTime").val(),
        	"endTime":$("#zhuanEndTime").val()
        },
        success : function(result){
        	newTotalElements=result.zhuan.totalElements;
        	$(".z").each(function(index,element){
    			$(element).find("li a").html("共 "+newTotalElements+" 条数据");
    		});
        }
	});
	
	return newTotalElements;
}
function getZhuanxianTotalElements(){
	var newTotalElements=0;
	$.ajax({
		url : ctx+'/chart/driverOrderDetailCount',
		type:'GET',
		async:false,
		dataType : 'json',
		data : {
			"driverId":driverId,
			"startTime":$("#zhuanxianStartTime").val(),
			"endTime":$("#zhuanxianEndTime").val()
		},
		success : function(result){
			newTotalElements=result.zhuanxian.totalElements;
			$(".zx").each(function(index,element){
				$(element).find("li a").html("共 "+newTotalElements+" 条数据");
			});
		}
	});
	
	return newTotalElements;
}

function getFreightTotalElements(){
	var newTotalElements=0;
	$.ajax({
        url : ctx+'/chart/driverOrderDetailCount',
        type:'GET',
        async:false,
        dataType : 'json',
        data : {
        	"driverId":driverId,
        	"startTime":$("#freightStartTime").val(),
        	"endTime":$("#freightEndTime").val()
        },
        success : function(result){
        	newTotalElements=result.freight.totalElements;
        	$(".f").each(function(index,element){
    			$(element).find("li a").html("共 "+newTotalElements+" 条数据");
    		});
        }
	});
	
	return newTotalElements;
}
Date.prototype.Format = function(fmt) 
{ 
  var o = { 
    "M+" : this.getMonth()+1,                 //月份 
    "d+" : this.getDate(),                    //日 
    "h+" : this.getHours(),                   //小时 
    "m+" : this.getMinutes(),                 //分 
    "s+" : this.getSeconds(),                 //秒 
    "q+" : Math.floor((this.getMonth()+3)/3), //季度 
    "S"  : this.getMilliseconds()             //毫秒 
  }; 
  if(/(y+)/.test(fmt)) 
    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
  for(var k in o) 
    if(new RegExp("("+ k +")").test(fmt)) 
  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  return fmt; 
}
